(function ($) {

  $.ajax({
    type: "post",
    url: "/pay/profitMonthly",
    dataType: "json",
    success: function (data ,textStatus, jqXHR) {
      console.log(data);
      "use strict"; // Start of use strict
      //line Morris
      var lineMorris = new Morris.Line({
        element: 'lineMorris',
        resize: true,
        data: data,
        xkey: "month",
        ykeys: ['profit'],
        labels: ['profit'],
        gridLineColor: '#eef0f2',
        lineColors: ['#E57498'],
        lineWidth: 2,
        hideHover: 'auto'
      });
    },
    error:function (XMLHttpRequest, textStatus, errorThrown) {
      alert("请求失败！");
    }
  });
  //barmorris
  var ctx = document.getElementById("barMorris");
  if (ctx === null) return;
  $.ajax({
    type: "post",
    url: "/register/registerNumsMonthly",
    dataType: "json",
    success: function (data ,textStatus, jqXHR) {
      console.log(data);
      "use strict"; // Start of use strict
      //line Morris
      var chart = Morris.Bar({
        element: 'barMorris',
        resize: true,
        data: data,
        xkey: "month",
        ykeys: ['nums'],
        labels: ['nums'],
        gridLineColor: '#eef0f2',
        lineColors: ['#E57498'],
        lineWidth: 2,
        hideHover: 'auto'
      });
    },
    error:function (XMLHttpRequest, textStatus, errorThrown) {
      alert("请求失败！");
    }
  });

  // morris donut charts
  if($("#donutMorris").length == 1){
   var $donutData = [
    { label: "Pending", value: 30 },
    { label: "Completed", value: 29 },
    { label: "Cancelled", value: 45 }
  ];
  Morris.Donut({
    element: 'donutMorris',
    data: $donutData,
    barSize: 0.1,
    labelColor: '#3e5569',
    resize: true, //defaulted to true
    colors: ['#FFAA2A', '#ef6e6e', '#22c6ab']
  });
  }
  
  // visit chart
  if($("#visitMorris").length == 1){
  var chart = Morris.Area({
    element: 'visitMorris',
    data: [{
      period: '2010',
      SiteA: 0,
      SiteB: 0,

    }, {
      period: '2011',
      SiteA: 130,
      SiteB: 100,

    }, {
      period: '2012',
      SiteA: 60,
      SiteB: 80,

    }, {
      period: '2013',
      SiteA: 180,
      SiteB: 200,

    }, {
      period: '2014',
      SiteA: 280,
      SiteB: 100,

    }, {
      period: '2015',
      SiteA: 170,
      SiteB: 150,
    },
    {
      period: '2016',
      SiteA: 200,
      SiteB: 80,

    }, {
      period: '2017',
      SiteA: 0,
      SiteB: 0,

    }],
    xkey: 'period',
    ykeys: ['SiteA', 'SiteB'],
    labels: ['Site A', 'Site B'],
    pointSize: 0,
    fillOpacity: 1,
    pointStrokeColors: ['#5867c3', '#00c5dc'],
    behaveLikeLine: true,
    gridLineColor: '#e0e0e0',
    lineWidth: 0,
    smooth: false,
    hideHover: 'auto',
    lineColors: ['#5867c3', '#00c5dc'],
    resize: true
  });
}
  
})(jQuery);
